package ${exceptionPackageName};

import org.apache.commons.lang3.StringUtils;

import lombok.Data;
import lombok.EqualsAndHashCode;
import net.newfirst.web.framework.common.ErrorCode;
import net.newfirst.web.framework.common.BaseException;
import net.newfirst.web.framework.response.WebResponse;

@Data
@EqualsAndHashCode(callSuper = false)
public class ${exceptionName} extends RuntimeException implements BaseException{
	

	private String errorCode;

	public ${exceptionName}() {
		this(ErrorCode.SYSTEM_ERROR.code);
	}
	
	public ${exceptionName}(String message) {
		super(message);
	}
	
	public ${exceptionName}(String errorCode, String message) {
		super(message);
		this.errorCode = errorCode;
	}

	public ${exceptionName}(WebResponse<?> response) {
		this(response.getMsg());
	}

	public ${exceptionName}(Enum<?> em){
		this(get(em).getErrorCode(),get(em).getMessage());
	}
	
	public ${exceptionName}(Enum<?> em,Object... param){
		this(get(em,param).getErrorCode(),get(em,param).getMessage());
	}

	private static ${exceptionName} get(Enum<?> em,Object... param){
		String errorCode = null;
		String errorMessage = null;
		if(em instanceof ErrorCode){
			errorCode = ((ErrorCode) em).code;
			errorMessage = ((ErrorCode) em).getErrorMessage(param);
		}else {
			errorCode = ErrorCode.SYSTEM_ERROR.code;
			errorMessage = ErrorCode.SYSTEM_ERROR.value;
		}
		return new ${exceptionName}(errorCode,errorMessage);
	}

	public ${exceptionName}(Throwable cause) {
		super(cause);
	}

	public ${exceptionName}(String message, Throwable cause) {
		super(message, cause);
	}

	public String getBaseErrorCode() {
		return StringUtils.isNotBlank(errorCode) ? this.errorCode:ErrorCode.SYSTEM_ERROR.code;
	}

	public String getBaseErrorMessage() {
		return super.getMessage();
	}
}
